home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------------------
-
- FILENAME
- StartJobMessage.c
-
- DESCRIPTION
- This file contains the message procedure that will be invoked when the Printing Manager
- issues the StartJob message. The routine which is called is StartJobMessageProc.
- Depending upon the effects the user selected in the Addition's Print dialog panel,
- StartJobMessageProc will invoke routines in the Additions.c file to produce the
- desired effects.
-
- COPYRIGHT
- Copyright Apple Computer, Inc. 1991
- All rights reserved.
-
- INTERFACE ROUTINES
- StartJobMessageProc
-
- MODIFICATION HISTORY
- 05/15/91 ALA Initial Implementation
-
-
- ------------------------------------------------------------------------------- */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Dialogs.h>
- #include <TextEdit.h>
- #include <OSUtils.h>
- #include <Packages.h>
- #include <ToolUtils.h>
- #include <Menus.h>
- #include <String.h>
- #include <Printing.h>
-
- #include <graphics routines.h>
- #include <graphics libraries.h>
- #include <Font Library.h>
-
- #include <Collections.h>
- #include <Messages.h>
-
- #include <PrintingManager.h>
- #include <PrintingMessages.h>
-
- #include "Utilities.h"
- #include "Additions.h"
-
-
- /*================================== MESSAGE INTERFACE ROUTINES ==================================*/
-
-
- /* ===== CleanupStartJobMessageProc =====
-
- CleanupStartJobMessageProc is the extension's routine which will be invoked when Printing issues a
- CleanupStartJob message. If the StartJobMessageProc routine had allocated some memory, this
- routine woulkd deallocate it and then call Forward_CleanupStartJob. As it is, this
- routine only calls Forward_CleanupStartJob.
- */
- void CleanupStartJobMessageProc(void)
- {
-
- /* Simply forward the cleanup message to others in the chain */
- Forward_GXCleanupStartJob();
- }
- /* CleanupStartJobMessageProc */
-
-
- /* ===== StartJobMessageProc =====
-
- StartJobMessageProc is the extension's routine which will be invoked when Printing issues a
- StartJob message. This routine will first make sure the job is started by calling
- Forward_StartJob. Once the job is started, it determines if a cover page should
- be added to the beginning of the document. If so, it creates a cover page and adds it
- to the file by issuing the Send_SpoolPage message with the newly created page. If no cover
- page is to be added, the routine returns after calling Forward_StartJob.
- */
- OSErr StartJobMessageProc(StringPtr docName, long pageCount) // (in) name of the document
- {
-
- OSErr anErr;
- gxShape coverPage;
- Collection jobCollection;
- AdditionsCollection additionsConfig;
-
- gxJob printJob = GXGetJob();
-
- /* Get reference to the print Job's collection */
- jobCollection = GXGetJobCollection(printJob);
-
- /* Fetch the Additions's collection we created at Print dialog time */
- anErr = GetCollectionItem (jobCollection,
- kAdditionsCollectionType,
- gxPrintingTagID,
- nil,
- &additionsConfig);
-
-
- /* if the pagecount is zero, we don't increment pageCount. pageCount = 0 */
- /* signals the spooling dialog what string to display. */
- if ((additionsConfig.addCoverPage) && (pageCount > 0))
- ++pageCount;
-
-
- /* Make sure the job is started first */
- anErr = Forward_GXStartJob(docName, pageCount);
-
-
- if (anErr == noErr)
- {
-
- /* Fetch the Additions's collection we created at Print dialog time */
- anErr = GetCollectionItem (jobCollection,
- kAdditionsCollectionType,
- gxPrintingTagID,
- nil,
- &additionsConfig);
- if (anErr == noErr)
- {
- /* If user selected the "cover page first" option, add the cover page to the spool file */
- if ( (additionsConfig.addCoverPage) && (additionsConfig.coverPage == kCoverPageFirst) )
- {
- gxFormat theFormat;
- gxJobInfo printerInfo;
-
- /* Get the format we should use for the cover page */
- theFormat = GXGetJobFormat(printJob, 1);
-
- /* Get the general printing info. collection item */
- anErr = GetCollectionItem (jobCollection,
- gxJobTag,
- gxPrintingTagID,
- nil,
- &printerInfo);
- if (anErr == noErr)
- {
- /* Create the cover page shape */
- anErr = ComposeCoverPage(&coverPage, theFormat, &printerInfo);
- if (anErr == noErr)
- {
- /* Spool the shape into the file */
- anErr = Send_GXPrintPage (theFormat, coverPage);
-
- /* Dump the shape since we no longer need it */
- GXDisposeShape(coverPage);
- }
- }
- }
-
- if (anErr == noErr)
- {
- /* If we're serializing copies, save the ending serial number in the next batch */
- if (additionsConfig.serializeCopies)
- {
- /* Compute the ending serial number */
- additionsConfig.nextEndSerialNum += GetCopiesFromJob(jobCollection) - 1;
-
- /* Update the config data in the job collection */
- anErr = AddCollectionItem( jobCollection,
- kAdditionsCollectionType,
- gxPrintingTagID,
- sizeof(AdditionsCollection),
- &additionsConfig);
- }
- }
-
- /* If we encountered an error, force a cleanup of StartJob */
- if (anErr != noErr)
- GXCleanupStartJob();
- }
- else // T => no config; don't do anything
- anErr = noErr;
- }
-
- return(anErr);
- }
- /* StartJobMessageProc */
-